<?php namespace Admin\Controller;
use Hdphp\Controller\Controller;
//标签管理控制器
class TagController extends CommonController{
	private $model;
	public function __init(){
		parent::__init();
		//实例化tag
		$this->model = new \Common\Model\tag;
	}
	//添加标签
	public function add(){
		if(IS_POST){
		   if(!$this->model->store()) View::error($this->model->getError());;
			View::success('添加成功',U('index'));
		}
	    View::make();
	}
	
	//展示标签
	public function index(){
		//获得所有标签
		$data = $this->model->get();
		View::with('data',$data);
	    View::make();
	}
	
	//编辑标签
	public function edit(){
		//2.修改
		if(IS_POST){
		   	if(!$this->model->edit()) View::error($this->model->getError());
			View::success('修改成功',U('index'));
		}
		//1.获取就数据
		$tid = Q('get.tid',0,'intval');
		$oldData = $this->model->where("tid={$tid}")->find();
		View::with('oldData',$oldData);
		//载入模板
	    View::make();
	}
	
	//删除标签
	public function del(){
		//获得get过来的tid
		$tid = Q('get.tid',0,'intval');
		//删除对应数据
		$this->model->where("tid={$tid}")->delete();
		//成功提示
		View::success('删除成功');
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}

 ?>